package cn.itcast.day05.exception03;

import java.util.Scanner;

/*
   模拟注册功能

   1.定义数组,存储几个用户名
   2.键盘录入一个名字,判断在不在数组中
   3.如果在,直接抛出一个注册异常
   4.否则,注册成功
 */
public class Test {
    public static void main(String[] args) {
        String[] name = {"张无忌","曹云金","孟鹤堂","柳岩"};
        method(name);
    }

    private static void method(String[] name){
        Scanner sc = new Scanner(System.in);
        System.out.println("请你输入要注册的名字:");
        String username = sc.next();

        for (int i = 0; i < name.length; i++) {
            if (username.equals(name[i])){
                throw new RegisterException("用户名已经存在!");
            }
        }
        System.out.println("注册成功");
    }
}
